<template>
  <div class="base-container">
    <t-form ref="form" :data="queryParams" label-width="80"
      @submit="() => { this.pagination.current = 1; this.queryParams.pageNum = 1; this.getList() }"
      @reset="() => { this.pagination.current = 1; this.queryParams.pageNum = 1; this.getList() }">
      <t-row style="border-bottom: 1px solid #E5E6EB;margin-bottom: 10px">
        <t-col :span="11" class="query-form-inline">
          <t-form-item label="申报年度" name="year">
            <t-date-picker style="width: 240px" v-model="queryParams.year" mode="year" clearable />
          </t-form-item>
          <t-form-item label="成果名称" name="name">
            <t-input v-model="queryParams.name" clearable placeholder="请输入成果名称" style="width: 240px" />
          </t-form-item>
          <t-form-item label="应用领域" name="applicationField">
            <t-select style="width: 240px" clearable v-model="queryParams.applicationField"
              :options="dict.type.application_field">
            </t-select>
          </t-form-item>
          <t-form-item label="创新类别" name="innovationCategory">
            <t-select style="width: 240px" clearable v-model="queryParams.innovationCategory"
              :options="dict.type.innovation_category">
            </t-select>
          </t-form-item>
          <t-form-item label="主要完成人员" name="leaderName">
            <t-input v-model="queryParams.leaderName" clearable placeholder="请输入全名" style="width: 240px" />
          </t-form-item>
          <t-form-item label="归口管理单位" name="managerIdList">
            <t-select multiple @change="getList" style="width: 300px" :keys="{ label: 'deptName', value: 'id' }"
              :options="deptManagerOptions" clearable filterable v-model="queryParams.managerIdList"></t-select>
          </t-form-item>
        </t-col>
        <t-col :span="1" class="operation-container">
          <t-button theme="primary" type="submit"> 查询</t-button>
          <t-button theme="default" variant="outline" type="reset">重置</t-button>
        </t-col>
      </t-row>
    </t-form>
    <!--    <div class="btn-group-inline">-->
    <!--      <t-tag theme="primary" variant="outline" size="large">年度名额：{{quotaData.quota}}</t-tag>-->
    <!--      <t-tag theme="primary" variant="outline" size="large">年度剩余名额：{{quotaData.remainData}}</t-tag>-->
    <!--    </div>-->
    <t-table rowKey="id" :data="data" :columns="columns" hover :pagination="pagination" :loading="dataLoading">
      <template #name="{ row }">
        <t-link @click="dialog.objId = row.id; dialog.header = row.name; dialog.open_innovation_detail = true"
          hover="color" theme="primary">{{ row.name }}</t-link>
      </template>
      <template #applicationField="{ row }">
        {{ row.applicationField | filterByDict(dict.type.application_field) }}
      </template>
      <template #innovationCategory="{ row }">
        {{ row.innovationCategory | filterByDict(dict.type.innovation_category) }}
      </template>
      <template #innovationStatus="{ row }">
        <t-tag @click="dialog.header = '审批记录'; dialog.objId = row.id; dialog.open_approve_list = true"
          class="cursor-pointer" :theme="handleTheme(row.innovationStatus, dict.type.innovation_status)"
          variant="light">
          {{ row.innovationStatus | filterByDict(dict.type.innovation_status) }}
        </t-tag>
      </template>
      <!--      <template #approveStatus="{ row }">-->
      <!--        <t-tag v-if="row.approveStatus === '2'" theme="primary" variant="light">审核中</t-tag>-->
      <!--        <t-tag v-else-if="row.approveStatus === '1'" theme="warning" variant="light">暂存</t-tag>-->
      <!--        <t-tag v-else-if="row.approveStatus === '3'" theme="success" variant="light">通过</t-tag>-->
      <!--        <t-tag v-else-if="row.approveStatus === '4'" theme="danger" variant="light">退回</t-tag>-->
      <!--        <t-tag v-else theme="warning" variant="light">未提交</t-tag>-->
      <!--      </template>-->
      <template #op="{ row }">
        <t-button
          @click="dialog.header = row.name; dialog.objId = row.id; dialog.editOpen = false; dialog.open_detail = true"
          size="small" variant="text" class="t-button-link">
          <t-icon name="info-circle" slot="icon" />
          推荐详情
        </t-button>
      </template>
    </t-table>
    <recommend-detail-dialog :editOpen="dialog.editOpen" :header="dialog.header" :objId="dialog.objId"
      :visible.sync="dialog.open_detail" v-if="dialog.open_detail"></recommend-detail-dialog>
    <approve-list :header="dialog.header" :objId="dialog.objId" :visible.sync="dialog.open_approve_list"
      v-if="dialog.open_approve_list"></approve-list>
    <innovation-detail-dialog :header="dialog.header" :objId="dialog.objId"
      :visible.sync="dialog.open_innovation_detail" v-if="dialog.open_innovation_detail"></innovation-detail-dialog>

  </div>
</template>

<script>
import RecommendDetailDialog from "./components/recommend-detail-dialog.vue";
import ApproveList from "../approve/components/approve-list.vue";
import innovationDetailDialog from "../innovation/components/innovation-detail-dialog.vue";

export default {
  name: "recommend-complete",
  dicts: ["application_field", "innovation_category", "approve_status", "innovation_status"],
  components: {
    RecommendDetailDialog,
    ApproveList,
    innovationDetailDialog
  },
  data () {
    return {
      deptManagerOptions: [],
      quotaData: {},
      dialog: {
        header: "",
        objId: 0,
        open_detail: false,
        editOpen: true,
        open_approve_list: false,
        open_innovation_detail: false,
      },
      data: [],
      columns: [
        {
          colKey: "name",
          title: "成果名称",
          align: "center",
          width: 220
        },
        {
          colKey: "applicationProject",
          title: "应用项目",
          align: "center",
          // ellipsis: true
        },
        {
          colKey: "applicationField",
          title: "应用领域",
          align: "center",
          // ellipsis: true
        },
        {
          colKey: "innovationCategory",
          title: "创新类别",
          align: "center",
          // ellipsis: true
        },
        {
          colKey: "leaderName",
          title: "负责人",
          align: "center",
          // ellipsis: true
        },
        {
          colKey: "deptName",
          title: "工作单位",
          align: "center",

        },
        {
          colKey: "managerDeptName",
          title: "归口单位",
          align: "center",
        },
        {
          colKey: "innovationStatus",
          title: "成果状态",
          align: "center",
          width: 120
        },
        // {
        //   colKey: "approveStatus",
        //   title: "审批状态",
        //   align: "center",
        //   width:120
        // },

        {
          colKey: "createTime",
          title: "申报时间",
          align: "center",
          width: 200
        },
        {
          colKey: "op",
          title: "操作",
          align: "center",
          width: 200
        },
      ],
      dataLoading: false,
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        recommendType: '2',
        applicationField: '',
        innovationCategory: '',
        name: '',
        year: '',
        leaderName: '',
        managerIdList: [],
      },
      pagination: {
        current: 1,
        pageSize: 10,
        total: 0,
        showPageSize: true,
        pageSizeOptions: [10, 20, 30, 50],
        showFirstAndLastPageBtn: false,
        onChange: (pageInfo) => {
          Object.assign(this.pagination, pageInfo)
          this.queryParams.pageNum = pageInfo.current || 1;
          this.queryParams.pageSize = pageInfo.pageSize;
          this.getList()
        },
      },
    }
  },
  created () {
    this.getList();
    // this.getRemainingQuota();
    this.getManagementList();
  },
  methods: {
    getManagementList () {
      this.$api.system.dept.getManagementList().then((res) => {
        this.deptManagerOptions = res.data;
      }).catch((e) => {
        this.$message.error(e.toString());
      });
    },
    getRemainingQuota () {
      this.$api.wcx.apply.getRemainingQuota(this.$store.state.user.deptId).then(res => {
        this.quotaData = res.data;
      }).catch((e) => {
        this.$message.error(e.toString());
      });
    },
    getList () {
      this.dataLoading = true;
      this.$api.wcx.innovation.recommendList(this.queryParams).then(
        (res) => {
          this.data = res.rows;
          this.pagination.total = res.total;
          this.dataLoading = false;
        }).catch((e) => {
          this.dataLoading = false;
          this.$message.error(e.toString());
        });
    },
  }
}
</script>
